package op;

import com.sun.jna.Native;
import com.sun.jna.platform.win32.COM.util.annotation.ComMethod;
import com.sun.jna.platform.win32.COM.util.annotation.ComObject;
import com.sun.jna.platform.win32.Variant;
import com.sun.jna.win32.StdCallLibrary;
/**
 * op插件路径
 */
class OpDLLPath {
    public static String toolsPath = "";
    public static String opPath ="";

    public static void setOpPath(String opPath) {
        OpDLLPath.opPath = opPath;
    }
    public static String getOpPath() {
        return OpDLLPath.opPath;
    }
    public static void setToolsPath(String toolsPath) {
        OpDLLPath.toolsPath = toolsPath;
    }
    public static String getToolsPath() {
        return OpDLLPath.toolsPath;
    }
}

//注册opsoft插件
interface RegisterTool extends StdCallLibrary {
    //op插件的tools.dll的绝对路径  x86使用tools_86.dll  x64使用tools.dll
    RegisterTool INSTANCE = (RegisterTool) Native.load(OpDLLPath.getToolsPath(), RegisterTool.class);
    int setupA(String path);
}

@ComObject(progId = "op.opsoft")
public interface OpSoft {

    static boolean register() {
        //op插件的绝对路径 x86使用op_x86.dll  x64使用op_x64.dll
        return RegisterTool.INSTANCE.setupA(OpDLLPath.getOpPath()) == 1;
    }

    //================================ 基础功能 ===========================
    /**
     * 返回 op 插件的版本号
     * @return op 插件的版本号
     */

    @ComMethod
    String ver();

    /**
     * 设置全局路径,设置了此路径后,所有接口调用中,相关的文件都相对于此路径. 比如图片,字库等.
     * @param path 路径
     * @return
     */
    @ComMethod
    int setPath(String path);

    /**
     * 获取全局路径
     * @return 返回当前设置的全局路径
     */
    @ComMethod
    String getPath();

    /**
     * 获取插件目录
     * @return 返回当前插件所在路径
     */
    @ComMethod
    String getBasePath();

    /**
     * 返回当前对象的 ID 值，这个值对于每个对象是唯一存在的。可以用来判定两个对象是否一致
     *
     */
    @ComMethod
    int getID();
    /**
     * 获取最后一次错误信息
     * @return 返回最后一次错误信息 0: 表示无错误
     */
    @ComMethod
    int getLastError();

    /**
     * 设置是否弹出错误信息,默认是打开
     * @param show 0:关闭，1:显示为信息框，2:保存到文件,3:输出到标准输出
     * @return 0-成功，1-失败
     */
    @ComMethod
    int setShowErrorMsg(int show);

    @ComMethod
    int sleep(int millisecond);

    @ComMethod
    void injectDll(String process_name, String dll_name, long ret);

    @ComMethod
    int enablePicCache(int enable);

    @ComMethod
    int capturePre(String file);

    @ComMethod
    int setScreenDataMode(int mode);

    //================================ 鼠标功能 ===========================

    @ComMethod
    int getCursorPos(Variant.VARIANT intx, Variant.VARIANT inty);

    @ComMethod
    int moveR(int rx, int ry);

    @ComMethod
    int moveTo(int x, int y);

    @ComMethod
    String moveToEx(int x, int y, int w, int h);

    @ComMethod
    int leftClick();

    @ComMethod
    int leftDoubleClick();

    @ComMethod
    int leftDown();

    @ComMethod
    int leftUp();

    @ComMethod
    int middleClick();

    @ComMethod
    int middleDown();

    @ComMethod
    int middleUp();

    @ComMethod
    int rightClick();

    @ComMethod
    int rightDown();

    @ComMethod
    int rightUp();

    @ComMethod
    int wheelDown();

    @ComMethod
    int wheelUp();

    @ComMethod
    int setMouseDelay(String type, int delay);

    //================================ 窗口绑定功能 ===========================

    @ComMethod
    int bindWindow(long hwnd, String display, String mouse, String keypad, int mode);

    @ComMethod
    int unBindWindow();

    @ComMethod
    long getBindWindow();

    @ComMethod
    int isBind();

    //================================ 图片处理功能 ===========================
    @ComMethod
    int capture(int x1, int y1, int x2, int y2, String file);

    @ComMethod
    int cmpColor(int x, int y, String color, double sim);

    @ComMethod
    int findColor(int x1, int y1, int x2, int y2, String color, double sim, int dir,
                     Variant.VARIANT intX, Variant.VARIANT intY);

    @ComMethod
    String findColorEx(int x1, int y1, int x2, int y2, String color, double sim, int dir);

    @ComMethod
    int findMultiColor(int x1, int y1, int x2, int y2, String first_color, String offset_color,
                          double sim, int dir, Variant.VARIANT intX, Variant.VARIANT intY);

    @ComMethod
    String findMultiColorEx(int x1, int y1, int x2, int y2, String first_color, String offset_color, double sim, int dir);

    @ComMethod
    int findPic(int x1, int y1, int x2, int y2, String pic_name, String delta_color, double sim,
                   int dir, Variant.VARIANT intX, Variant.VARIANT intY);

    @ComMethod
    String findPicEx(int x1, int y1, int x2, int y2, String pic_name, String delta_color, double sim, int dir);

    @ComMethod
    String findPicExS(int x1, int y1, int x2, int y2, String pic_name, String delta_color, double sim, int dir);

    @ComMethod
    int findColorBlock(int x1, int y1, int x2, int y2, String color, double sim,
                          int count, int width, int height, Variant.VARIANT intX, Variant.VARIANT intY);

    @ComMethod
    String findColorBlockEx(int x1, int y1, int x2, int y2, String color, double sim, int count, int width, int height);

    @ComMethod
    String getColor(int x, int y);

    @ComMethod
    int setDisplayInput(String mode);

    @ComMethod
    int loadPic(String pic_name);

    @ComMethod
    int freePic(String pic_name);

    @ComMethod
    int loadMemPic(String file_name, int data, int size);

    @ComMethod
    int getScreenData(int x1, int y1, int x2, int y2);

    @ComMethod
    int getScreenDataBmp(int x1, int y1, int x2, int y2, Variant.VARIANT data, Variant.VARIANT size);

    @ComMethod
    void getScreenFrameInfo(Variant.VARIANT frame_id, Variant.VARIANT time);

    @ComMethod
    String matchPicName(String pic_name);


    //================================ 窗口操作功能 ===========================

    @ComMethod
    String enumWindow(long parent, String title, String class_name, int filter);

    @ComMethod
    String enumWindowByProcess(String process_name, String title, String class_name, int filter);

    @ComMethod
    String enumProcess(String name);

    @ComMethod
    int clientToScreen(long hwnd, Variant.VARIANT x, Variant.VARIANT y);

    @ComMethod
    int findWindow(String clazz, String title);

    @ComMethod
    int findWindowByProcess(String process_name, String clazz, String title);

    @ComMethod
    int findWindowByProcessId(int process_id, String clazz, String title);

    @ComMethod
    int findWindowEx(long parent, String clazz, String title);

    @ComMethod
    int getClientRect(long hwnd, Variant.VARIANT x1, Variant.VARIANT y1, Variant.VARIANT x2, Variant.VARIANT y2);

    @ComMethod
    int getClientSize(long hwnd, Variant.VARIANT width, Variant.VARIANT hight);

    @ComMethod
    long getForegroundFocus();

    @ComMethod
    long getForegroundWindow();

    @ComMethod
    long getMousePointWindow();

    @ComMethod
    long getPointWindow(int x, int y);

    @ComMethod
    String getProcessInfo(int pid);

    @ComMethod
    long getSpecialWindow(int flag);

    @ComMethod
    long getWindow(int hwnd, int flag);

    @ComMethod
    String getWindowClass(long hwnd);

    @ComMethod
    int getWindowProcessId(long hwnd);

    @ComMethod
    String getWindowProcessPath(long hwnd);

    @ComMethod
    int getWindowRect(long hwnd, Variant.VARIANT x1, Variant.VARIANT y1, Variant.VARIANT x2, Variant.VARIANT y2);

    @ComMethod
    int getWindowState(long hwnd, int flag);

    @ComMethod
    String getWindowTitle(long hwnd);

    @ComMethod
    int moveWindow(long hwnd, int x, int y);

    @ComMethod
    int screenToClient(long hwnd, Variant.VARIANT x, Variant.VARIANT y);

    @ComMethod
    int setClientSize(long hwnd, int width, int height);

    @ComMethod
    int setWindowState(long hwnd, int flag);

    @ComMethod
    int setWindowSize(long hwnd, int width, int height);

    @ComMethod
    int setWindowText(long hwnd, String title);

    @ComMethod
    int setWindowTransparent(long hwnd, int trans);

    @ComMethod
    int sendString(long hwnd, String str);

    @ComMethod
    int sendStringIme(long hwnd, String str);

    //================================ 键盘功能 ===========================

    @ComMethod
    int getKeyState(int vk_code);

    @ComMethod
    int keyDown(int vk_code);

    @ComMethod
    int keyUp(int vk_code);

    @ComMethod
    int keyDownChar(String key_str);

    @ComMethod
    int keyUpChar(String key_str);

    @ComMethod
    int waitKey(int vk_code, String time_out);

    @ComMethod
    int keyPress(int vk_code);

    @ComMethod
    int keyPressChar(String key_str);

    @ComMethod
    int setKeypadDelay(String type, int delay);


    //================================ ocr功能 ===========================

    @ComMethod
    int setDict(int index, String file);

    @ComMethod
    int setMemDict(int index, byte[] data, int size);

    @ComMethod
    int useDict(int index);

    @ComMethod
    String ocr(int x1, int y1, int x2, int y2, String color_format, double sim);

    @ComMethod
    String ocrEx(int x1, int y1, int x2, int y2, String color_format, double sim);

    @ComMethod
    String ocrAuto(int x1, int y1, int x2, int y2, double sim);

    @ComMethod
    String ocrFromFile(String file_name, String color_format, double sim);

    @ComMethod
    String ocrAutoFromFile(String file_name, double sim);

    @ComMethod
    int findStr(int x1, int y1, int x2, int y2, String str, String color_format,
                   double sim, Variant.VARIANT intX, Variant.VARIANT intY);

    @ComMethod
    String findStrEx(int x1, int y1, int x2, int y2, String str, String color_format, double sim);

    @ComMethod
    String findLine(int x1, int y1, int x2, int y2, String color_format, double sim);

    //================================ 一些算法功能 ===========================

    @ComMethod
    String aStarFindPath(int mapWidth, int mapHeight, String disable_points, int beginX, int beginY, int endX, int endY);

    //================================ 内存操作功能 ===========================

    @ComMethod
    int writeData(long hwnd, String address, String data, int size);

    @ComMethod
    int readData(long hwnd, String address, int size);

    //================================ 系统功能 ===========================

    @ComMethod
    int runApp(String app_path, int mode);

    @ComMethod
    int winExec(String cmdline, int cmdshow);

    @ComMethod
    String getCmdStr(String cmdline, int millseconds);

    @ComMethod
    int setClipboard(String str);

    @ComMethod
    String getClipboard();

    @ComMethod
    int delay(int mis);

    @ComMethod
    int delays(int mis_min, int mis_max);
}
